'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/pages/pub/index_newslist 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, type, page, indexTab,appid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------

		if (type == "onReachBottom") {
			//====加载首页资讯====
			let newslist = await db.collection('a_article').where({
				cate: indexTab,
				appid: _.or(_.eq([]), _.in([appid])) //数组为空或包含了appid,既满足条件
			}).skip(page * 20).orderBy('_add_time', 'desc').limit(20).get()
			res.newslist = newslist.data
			//====加载首页资讯====
		}
		
		if (type == "onload") {
			//====加载资讯====
			let newslist = await db.collection('a_article').where({
				cate: indexTab,
				appid: _.or(_.eq([]), _.in([appid])) //数组为空或包含了appid,既满足条件
			}).orderBy('_add_time', 'desc').limit(20).get()
			res.newslist = newslist.data
			//====加载资讯====
		}


		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
